<!-- 搜索表单 -->
<template>
  <el-form
    label-width="77px"
    class="ele-form-search"
    @keyup.enter.native="search"
    @submit.native.prevent
  >
    <el-row :gutter="15">
     
      <el-col :lg="6" :md="12" v-if="platform_id==0">
        <el-form-item label="平台信息:">
          <el-input
            clearable
            v-model="where.platform_name"
            placeholder="平台名称或手机号"
          />
        </el-form-item>
      </el-col>

           <el-col :lg="6" :md="12">
        <el-form-item label="订单号:">
          <el-input
            clearable
            v-model="where.order_number"
            placeholder="订单号"
          />
        </el-form-item>
      </el-col>



         <el-col :lg="6" :md="12"  v-if="platform_id > 0">
        <el-form-item label="店铺信息:">
          <el-input
            clearable
            v-model="where.store_telphone"
            placeholder="店铺"
          />
        </el-form-item>
      </el-col>
      
         <el-col :lg="6" :md="12"  v-if="platform_id > 0">
        <el-form-item label="用户信息:">
          <el-input
            clearable
            v-model="where.user_name"
            placeholder="用户信息"
          />
        </el-form-item>
      </el-col>
       <el-col :lg="6" :md="12">
        <el-form-item label="时间:">
          <el-date-picker
            v-model="dateRange"
            type="datetimerange"
            :picker-options="pickerOptions"
            unlink-panels
            range-separator="-"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            value-format="yyyy-MM-dd HH:mm:ss"
            class="ele-fluid"
          />
        </el-form-item>
      </el-col>
      <el-col :lg="6" :md="12">
        <div class="ele-form-actions">
          <el-button
            type="primary"
            icon="el-icon-search"
            class="ele-btn-icon"
            @click="search"
          >
            查询
          </el-button>
          <el-button @click="reset">重置</el-button>
        </div>
      </el-col>
    </el-row>
  </el-form>
</template>

<script>
const DEFAULT_WHERE = {
  nickname: '',
  telphone: '',
  p_nickname: ''
};

export default {
  name: 'SponsorSearch',
  data() {
    return {
      // 表单数据
      where: { ...DEFAULT_WHERE },
      platform_id:'',
         dateRange: [],
        // 日期时间选择器快捷项
        pickerOptions: {
          shortcuts: [
            {
              text: '最近一周',
              onClick(picker) {
                const end = new Date();
                const start = new Date();
                start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
                picker.$emit('pick', [start, end]);
              }
            },
            {
              text: '最近一个月',
              onClick(picker) {
                const end = new Date();
                const start = new Date();
                start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
                picker.$emit('pick', [start, end]);
              }
            },
            {
              text: '最近三个月',
              onClick(picker) {
                const end = new Date();
                const start = new Date();
                start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
                picker.$emit('pick', [start, end]);
              }
            }
          ]
        }
    };
  },
  created(){
  this.platform_id=localStorage.getItem('platform_id')

  },
  methods: {
    /* 搜索 */
    
   search() {
        const [d1, d2] = this.dateRange ?? [];
        this.$emit('search', {
          ...this.where,
          start_time: d1 ? d1  : '',
          end_time: d2 ? d2  : ''
        });
      },
    /*  重置 */
    reset() {
      this.where = { ...DEFAULT_WHERE };
      this.search();
    }
  }
};
</script>
